import { service, crudParamsSerializer } from '@/utils/request'
import { CreateQueryParams } from '@nestjsx/crud-request'
import { Album } from './album.dto'

const defaultAlbumData: Partial<Album> = {
  title: '',
  description: '',
  visible: false,
  favCount: 0
}

function getAlbums (params: CreateQueryParams) {
  return service.get<Album[]>(
    '/resources/albums',
    {
      params,
      paramsSerializer: crudParamsSerializer
    }
  )
}

function getAlbumById (id: number | string, params: CreateQueryParams) {
  return service.get<Album>(
    `/resources/albums/${id}`,
    {
      params,
      paramsSerializer: crudParamsSerializer
    }
  )
}

function checkFavAlbum (id: number | string) {
  return service.request({
    url: `/resources/albums/${id}/fav`,
    method: 'get'
  })
}

function setFavAlbum (id: number | string) {
  return service.request({
    url: `/resources/albums/${id}/fav`,
    method: 'post'
  })
}

function removeFavAlbum (id: number | string) {
  return service.request({
    url: `/resources/albums/${id}/fav`,
    method: 'delete'
  })
}

export { defaultAlbumData, getAlbums, getAlbumById, checkFavAlbum, setFavAlbum, removeFavAlbum }
